<div class="wrapper">
    <div>
        <div class="box box-top">
            <!-- /.box-header -->
            <!-- form start -->
            <form id="riderForm" role="form" action="${base}/admin/rider/saveForCompany" method="post">
                <input type="hidden" name="id" value="${(rider.id)!}">
                <input type="hidden" name="companyId" value="${rider.companyId!}">
                <div class="box-body">
                    <div class="form-group">
                        <label for="phone">手机号</label>
                        ${(rider.phone)!''}
                        <input type="text" value="${(rider.phone)!''}" class="form-control" id="phone" name="phone" >
                    </div>
                    <div class="box-footer">
                        <button type="button" onclick="$('#riderForm').submit();" class="btn btn-primary">Save
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#riderForm").validate({
            submitHandler:function(form){
                submitRider();
            }
        });
    });
    function submitRider(){
        HF.ajaxFormSubmit('riderForm',function(result){
            alert("Save Success");
            document.location.reload();
        },function(e){ alert("Save Failure");});
    }
    function pushImg(obj) {

        var url = '${base}'+ "/admin/rider/titleImgeUpload"; //访问控制器是upload，后面必须加'/'否则会报错"org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.Mult...",但是如果是多级的URL【例如XX/XXX/00/upload/0】又没问题了.
        var files = $("#exampleInputFile").get(0).files[0]; //获取file控件中的内容

        var fd = new FormData();
        fd.append("uploadFile", files);
        $.ajax({
            type: "POST",
            contentType:false, //必须false才会避开jQuery对 formdata 的默认处理 , XMLHttpRequest会对 formdata 进行正确的处理
            processData: false, //必须false才会自动加上正确的Content-Type
            url: url,
            data: fd,
            success: function (msg) {

                var obj = eval('(' + JSON.stringify(msg) + ')');
                if(obj.SUCESS){
                    //填充图片
                    $("#titleImage").attr("src", obj.DATA);
                    $("#titleImage").css("width","150");
                    $("#titleImage").css("height","100");
                    //写入隐藏域
                    $("#annex").val(obj.DATA);
                }
            },
            error: function (msg) {
                //debugger;
                alert("error");
            }
        });
    }
</script>
